<template>
	<view class="page">
		<Search class="" @search='onSearch' placeholder="请输入关键字搜索" />
		<view class="tcard">
			<view class="tform">
				<view v-for="(item,indext) in typeList" :key="indext" @click="openQuestion(item,indext)">
					<view class="tform-item">
						<view class="start-center">
							<image class="img" v-if="item.icon" :src="hostApi+item.icon"></image>
							<image class="img" v-else src="/static/images/icon/jiuyizhinan.png"></image>
							<view>{{item.typeName}}</view>
						</view>
						<view class="label"><u-icon name="arrow-right"></u-icon></view>
					</view>
					<view v-if="indext==currentIndex" v-for="(itemq,indexq) in listQuestion" :key="indexq">
						<view class="question-name" @click.stop="toDetail(itemq)">{{itemq.question}}</view>
					</view>
				</view>

			</view>

		</view>
		<Button content="在线反馈" @click="toFeedBack"></Button>
	</view>
</template>

<script>
	import Search from '@/components/Search/searchEmpty.vue'
	import Button from "@/components/Button/Button.vue"
	import {
		questionSelect
	} from '../../api/question';
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	export default {
		components: {
			Search,
			Button
		},
		computed: {
			...mapGetters(['userInfo', "hostApi"]),

		},
		data() {
			return {
				question: '',
				typeList: [],
				listQuestion: [],
				typeId: -1,
				currentIndex: -1,
				listAll: [],
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				questionSelect({
					question: this.question
				}).then(res => {
					this.listAll = res;
					let map = new Map()
					res.forEach(item => {
						map.set(item.typeId, item)
					})
					this.typeList = Array.from(map).map(([key, value]) => value);
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url: `./Detail?item=` + JSON.stringify(item)
				})
			},
			openQuestion(typeItem, index) {
				if (this.currentIndex == index) {
					this.currentIndex = -1
					return
				}
				this.currentIndex = index
				this.listQuestion = this.listAll.filter(item => item.typeId == typeItem.id)
			},
			onSearch(val) {
				this.listQuestion = []
				this.typeList = []
				this.question = val
				this.currentIndex = -1
				this.init()

			},
			toFeedBack() {
				if (!this.userInfo) {
					this.$u.toast('请选择就诊卡')
					return;
				}
				uni.navigateTo({
					url: `/pages/Feedback/Feedback`
				})
			}
		}
	}
</script>

<style scoped>
	.img {
		width: 20px;
		height: 20px;
	}

	.question-name {
		text-indent: 2em;
		height: 15px;
		font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
		font-weight: 400;
		color: #999999;
		line-height: 15px;
		text-align: left;
		font-style: normal;
		text-transform: none;
		margin: 10px 0;
	}
</style>